<%@ page import="java.sql.Connection" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="java.sql.DriverManager" %>
<%@ page import="java.sql.SQLException" %><%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2018/4/2
  Time: 19:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>添加用户</title>
</head>
<body>
<p><a href="index.jsp">返回列表</a></p><br/>
<form method="post" action="" >
    用户名：<input name="username" type="text" id="username" class="username"></br>
    密码：<input name="password" type="text" id="password" class="password"></br>
    <input type="submit" id="input" value="添加">
</form>
<%
    request.setCharacterEncoding("UTF-8");
    String username=request.getParameter("username");
    String pass=request.getParameter("password");

    if (username==null||pass==null){

    }else {
        Connection connection=null;
        Statement statement=null;
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
            connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone=UTC&&characterEnconding=UTF-8",
                    "root",
                    "123456");
            statement=connection.createStatement();
            statement.executeUpdate("INSERT INTO t_users(username,password)VALUE ('"+username+"','"+pass+"')");
        }catch (ClassNotFoundException e){
            e.printStackTrace();
        }
        finally {
            try {
                connection.close();
                statement.close();
            }catch (SQLException e){
                e.printStackTrace();
            }
        }
    }
%>

</body>
</html>
